package at.sysarch.filter;

import java.io.StreamCorruptedException;
import java.util.LinkedList;
import java.util.List;

import at.pimpmypipe.filter.AbstractSink;
import at.sysarch.model.Line;

public class Sink extends AbstractSink<LinkedList<Line>> {
	
	private List<SinkCallback> _listeners;
	
	public Sink() {

		_listeners = new LinkedList<Sink.SinkCallback>();
	}

	/**
	 * Writes incoming results to each registered listener.
	 */
	@Override
	public void write(LinkedList<Line> value) throws StreamCorruptedException {

		for (SinkCallback callback: _listeners) {
			
			callback.updateSinkResult(value);
		}
	}
	
	public void addListener(SinkCallback callback) {
		
		_listeners.add(callback);
	}
	
	public void removeListener(SinkCallback callback) {
		
		_listeners.remove(callback);
	}
	
	public interface SinkCallback {
		
		public void updateSinkResult(List<Line> result);
	}
}
